//
//  Part6Wrapper.m
//  Dolphin
//
//  Created by Matthew on 12-2-17.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "Part6Wrapper.h"

#define MARGIN_EDGE     20

#import "ColorUtil.h"

@implementation Part6Wrapper

- (void) viewExit
{
    self.hidden = TRUE;
    
    if ([curNodeName isEqualToString:@"6i4"]) 
    {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"return_to_page_6" object:self];
    }
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        self.backgroundColor = [ColorUtil stringHexToUIColor:@"0xcdc19b"];
        
        // Initialization code
        UIButton * exitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImage * img = [UIImage imageNamed:@"exit_btn.png"];
        CGSize imgSz = img.size;
        [exitBtn setImage:img forState:UIControlStateNormal];
        [exitBtn setImage:[UIImage imageNamed:@"exit_btn.png"] forState:UIControlStateSelected];
        
        exitBtn.frame = CGRectMake(frame.size.width-imgSz.width-MARGIN_EDGE, frame.size.height-imgSz.height-MARGIN_EDGE, imgSz.width, imgSz.height);
        [exitBtn addTarget:self action:@selector(viewExit) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:exitBtn];
    }
    return self;
}

- (void) setPictureArray:(int) inTopStartIndex
             topEndIndex:(int) inTopEndIndex
                  prefix:(NSString *) inPrefix
                filetype:(NSString *) inFileType
                inWidth:(int) inW
                inHeight:(int) inH     
                    offX:(int) inOffX
                    offY:(int) inOffY
                   _name:(NSString *)inName
{ 
    threeSixtyMap = [[ThreeSixtyMap alloc] initWithFrame:CGRectMake((self.frame.size.width-inW)/2+inOffX,-120+inOffY,inW,inH)];
    threeSixtyMap.delegate = self;
    [self addSubview:threeSixtyMap];
    [self sendSubviewToBack:threeSixtyMap];
    
    NSMutableArray *arrA = [[NSMutableArray alloc] init];
    NSString *tempFileName;

    for (int i = inTopStartIndex; i<= inTopEndIndex; i++) 
    {
        if (i%2 == 1 || i == inTopStartIndex || i == inTopEndIndex) 
        {
            if (i<10) 
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@0%d",inPrefix,i];
            }
            else
            {
                tempFileName = [[NSString alloc] initWithFormat:@"%@%d",inPrefix,i];
            }
            [arrA addObject:tempFileName];
        }
    }
    
    [threeSixtyMap initTheMap2:arrA fileType:inFileType inId:0 inW:inW inH:inH];
    
    curNodeName = [[NSString alloc] initWithString:inName];
}

- (void) swipeUpWithMapId:(int)mapId
{

}

- (void) swipeDownWithMapId:(int)mapId
{

}

- (void) setSmallPicture:(NSString *)smallImg
                             msg:(NSString *) inMsg
{
     _smallImage = [[UIImageLayer alloc] initWithFrame:CGRectMake(MARGIN_EDGE,self.frame.size.height-MARGIN_EDGE-121,121, 121)];
    [ _smallImage initImage:smallImg useOriginalSize:TRUE ratioMode:TRUE layerInfo:Nil];
    [ _smallImage initHitMsg:inMsg];
    [self addSubview: _smallImage];
}

-(void) reset
{
    if (threeSixtyMap) 
    {
        [threeSixtyMap reset];
        [threeSixtyMap removeFromSuperview];
        [threeSixtyMap release];
        threeSixtyMap = nil;
    }
    
    if (_smallImage) {
        [_smallImage reset];
        [_smallImage removeFromSuperview];
        [_smallImage release];
        _smallImage = nil;
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc
{
    [super dealloc];
}

@end
